<?php

if(!defined('CMS_ADMIN')) {
	die("Illegal File Access");
}

$id = intval($_GET['id']);
$result = $db->sql_query("SELECT title, links, if_show FROM ".$prefix."_links WHERE id='$id'");
if(empty($id) || $db->sql_numrows($result) != 1) {
	header("Location: modules.php?f=".$adm_modname."");
	exit;
}

list($title, $links, $if_show) = $db->sql_fetchrow($result);

$err_title = $err_size ="";
if(isset($_POST['subup']) && $_POST['subup'] == 1) {
    $title = trim(stripslashes(resString($_POST['title'])));
		$links = trim(stripslashes(resString($_POST['links'])));
		$if_show = intval($_POST['ifshow']);
		$bmodule = $_POST['bmodule'];

	if(@in_array("all",$bmodule)) {$bmodule_up ="all"; }else{
		$bmodule_up = @implode("|",$bmodule);
	}
	if(empty($bmodule_up)) { $bmodule_up = "all"; }

	if(empty($title)) {
		$err_title = "<font color=\"red\">"._ERROR1."</font><br>";
		$err = 1;
	}

	if(empty($links) || !preg_match('!^http(s)?://!i', $links)) {
		$err_links = "<font color=\"red\">"._ERROR2."</font><br>";
		$err = 1;
	}

	if(!$err) {
		$db->sql_query("UPDATE ".$prefix."_links SET title='$title', links='$links', times='".time()."', if_show='$if_show' WHERE id='$id'");
		header("Location: modules.php?f=".$adm_modname."");
		updateadmlog($admin_ar[0], $adm_modname, _MODTITLE, _EDIT);
		exit;
	}
}

include("page_header.php");

echo "<script language=\"javascript\">\n";
	echo "	function check(f) {\n";
	echo "		if(f.title.value =='') {\n";
	echo "			alert('"._ERROR1."');\n";
	echo "			f.title.focus();\n";
	echo "			return false;\n";
	echo "		}	\n";
	echo "		if(f.links.value =='') {\n";
	echo "			alert('"._ERROR2."');\n";
	echo "			f.links.focus();\n";
	echo "			return false;\n";
	echo "		}	\n";

	echo "		if(f.bnid.value == 0) {\n";
	echo "			alert('"._ERROR4."');\n";
	echo "			f.bnid.focus();\n";
	echo "			return false;\n";
	echo "		}	\n";
	echo "		f.submit.disabled = true;\n";
	echo "		return true;	\n";
	echo "	}	\n";
	echo "</script>	\n";

echo "<form action=\"modules.php?f=$adm_modname&do=$do&id=$id\" method=\"POST\" enctype=\"multipart/form-data\" onsubmit=\"return check(this);\"><table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\" class=\"tableborder\">\n";
echo "<tr><td class=\"header\" colspan=\"2\">"._EDITMENU."</td></tr>";
echo "<tr>\n";
	echo "<td width=\"20%\" align=\"right\" class=\"row1\"><b>"._TITLE."</b></td>\n";
	echo "<td class=\"row2\"><input type=\"text\" name=\"title\" value=\"$title\" size=\"60\"></td>\n";
	echo "</tr>\n";
	echo "<tr>\n";
	echo "<td width=\"20%\" align=\"right\" class=\"row1\"><b>"._URL."</b> (http://...)</td>\n";
	echo "<td class=\"row2\"><input type=\"text\" name=\"links\" value=\"$links\" size=\"60\"></td>\n";
	echo "</tr>\n";
	
	
	echo "<tr>\n";
	echo "<td align=\"right\" class=\"row1\"><b>"._SHOW."</b></td>\n";
	if($if_show == 0) {
		echo "<td  class=\"row2\"><input type=\"radio\" name=\"ifshow\" value=\"1\">"._YES." &nbsp;&nbsp;"
		."<input type=\"radio\" name=\"ifshow\" value=\"0\" checked>"._NO."</td>\n";
	} else {
		echo "<td  class=\"row2\"><input type=\"radio\" name=\"ifshow\" value=\"1\" checked>"._YES." &nbsp;&nbsp;"
		."<input type=\"radio\" name=\"ifshow\" value=\"0\">"._NO."</td>\n";
	}
	echo "</tr>\n";
echo "<input type=\"hidden\" name=\"subup\" value=\"1\">";
echo "<tr><td class=\"row3\">&nbsp;</td><td class=\"row3\"><input type=\"submit\" name=\"submit\" value=\""._SAVECHANGES."\" class=\"input1\"></td></tr>";
echo "</table></form><br>";

include_once("page_footer.php");
?>